<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:frbr="http://vocab.org/frbr/core" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:dc="http://purl.org/dc/terms/" exclude-result-prefixes="frbr rdf dc">
    
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
    <xsl:template match="/">
        <resource>
            <xsl:apply-templates select="./*"/>
        </resource>
    </xsl:template>
    
    <xsl:template match="frbr:Manifestation">
        <instance>
            <xsl:attribute name="rdf:about"><xsl:value-of select="./@rdf:about" /></xsl:attribute>
            <xsl:apply-templates select="@*|node()"/>
        </instance>
    </xsl:template>
    <xsl:template match="frbr:Item">
        <item>
            <xsl:attribute name="rdf:about"><xsl:value-of select="./@rdf:about" /></xsl:attribute>
            <xsl:apply-templates />
        </item>
    </xsl:template>
    <xsl:template match="dc:BibliographicResource[@type='holding']">
        <holding>
            <xsl:attribute name="rdf:about"><xsl:value-of select="./@rdf:about" /></xsl:attribute>
            <xsl:apply-templates />
        </holding>
    </xsl:template>
    <xsl:template match="dc:Location[@type='library']">
        <library>
            <xsl:attribute name="rdf:about"><xsl:value-of select="./@rdf:about" /></xsl:attribute>
            <xsl:value-of select="./dc:title[@type='display']" />
        </library>
    </xsl:template>
    <xsl:template match="dc:Location[not(@type='library')]">
        <location>
            <xsl:copy-of select="@*" />
            <xsl:copy-of select="./dc:title[not(@type)]" />
            <xsl:apply-templates select="dc:Location[@type='library']" />
        </location>
    </xsl:template>
    <xsl:template match="status">
        <status>
            <xsl:attribute name="dc:date"><xsl:value-of select="./dc:date" /></xsl:attribute>
            <xsl:value-of select="./dc:description" />
        </status>
    </xsl:template>
    
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:copy-of select="text()|@*" />
            <xsl:apply-templates select="./*" />
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>